package com.springbootbooks.service.servicelmpl;

import com.springbootbooks.common.Result;
import com.springbootbooks.dao.UserMapper;
import com.springbootbooks.pojo.User;
import com.springbootbooks.service.UserService;
import com.springbootbooks.utils.FormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: lijiafen
 * @Date: 2022/1/21
 * @Time: 19:07
 * @E-amil: 2368044269@qq.com
 */
@Service
public class UserServiceLmpl implements UserService {

    @Autowired
    UserMapper mapper;

     /**
         * @Description: 注册用户
         * @Author: lijiafen
         * @Date: 2022/1/21
         * @time: 20:17
         */
    @Override
    public Result inertUser(User user) {
        System.out.println(user.getPhone());
        String phone = user.getPhone();
        if (phone==null)
        {
            return Result.getFailure().setDate("电话号码不能为空");
        }
        if (user.getPassWord()==null)
        {
            return Result.getFailure().setDate("密码不能为空");
        }
       if (!FormatUtils.isMobile(phone))
       {
           return Result.getSuccess().setDate("电话号码格式错误");
       }
        List<User> user1 = mapper.selectUserByphone(phone);
        if (user1.size()==0)
        {
            mapper.inertUser(user);
            return Result.getSuccess().setDate("注册成功");
        }else {
            return Result.getFailure().setDate("改电话已被注册");
        }
    }
}
